//---------------Sonic CD Push Button Script------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.PropertyValue	:	Object.Pressed

// Gravity
#alias 0	:	GRAVITY_GROUND

// Collision
#alias 1	:	PLAYER_COL_FLOOR

// Stage SFX
#alias 3	:	SFX_S_SWITCH

// Priority
#alias 0	:	PRIORITY_BOUNDS
#alias 1	:	PRIORITY_ACTIVE

sub ObjectPlayerInteraction	
	if Object.PropertyValue < 2
		if Object.Pressed == false
			if Player.YVelocity >= 0
				PlayerObjectCollision(C_BOX, -16, -8, 16, 8)
				if CheckResult == PLAYER_COL_FLOOR
					Object.Pressed = true
					Player.YPos   += 0x80000
					PlayStageSfx(SFX_S_SWITCH, false)
				else
					Object.Pressed = false
				end if
			else
				Object.Pressed = false
			end if
		else
			PlayerObjectCollision(C_TOUCH, -16, -1, 16, 8)
			if CheckResult == true
				Object.Pressed    = true
				Player.Gravity 	  = GRAVITY_GROUND
				Player.YVelocity  = 0
				Player.YPos = Player.CollisionBottom
				FlipSign(Player.YPos)
				Player.YPos 	<<= 16
				Player.YPos 	 += Object.YPos
			else
				Object.Pressed = false
				
				if Player.YVelocity > -1
					Player.Gravity   = GRAVITY_GROUND
					Player.YVelocity = 0
					Player.YPos   	 = Player.CollisionBottom
					FlipSign(Player.YPos)
					Player.YPos 	-= 8
					Player.YPos    <<= 16
					Player.YPos 	+= Object.YPos
				end if
			end if
		end if
	end if
end sub


sub ObjectDraw
	if Object.PropertyValue == 2
		DrawSprite(2)
	else
		DrawSprite(Object.Pressed)
	end if
end sub


sub ObjectStartup
	LoadSpriteSheet("R2/Objects.gif")

	SpriteFrame(-16, -8, 32, 16, 26, 35)	// #0 - Push Button inactive
	SpriteFrame(-16, 0, 32, 8, 26, 52)	// #1 - Push Button active
	SpriteFrame(-16, -8, 32, 16, 26, 61)	// #2 - Broken Push Button
	
	// Set this object to always active
	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[PushButton]
			Object[ArrayPos0].Priority = PRIORITY_ACTIVE
		end if
		ArrayPos0++
	loop
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(Object.PropertyValue)
end sub


sub RSDKLoad
	LoadSpriteSheet("R8/Objects.gif")

	SpriteFrame(-16, -8, 32, 16, 142, 98)	// #0 - Push Button inactive
	SpriteFrame(-16, 0, 32, 8, 142, 114)	// #1 - Push Button active

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub
